package com.lc.qianrenshiye.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/5.
 */
@HttpInlet(Conn.GAINS_GOODS)
public class LoanPost extends BaseAsyPost<LoanPost.LoanListEntity> {

    public String sid, pay, time, type, start, end;

    public LoanPost(AsyCallBack<LoanListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected LoanListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            LoanListEntity loanListEntity = new LoanListEntity();

            loanListEntity.knot = object.optString("knot");
            loanListEntity.nkont = object.optString("nkont");
            loanListEntity.total = object.optString("total");

            JSONArray array = object.optJSONArray("list");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject entityObject = array.optJSONObject(i);

                    LoanEntity loanEntity = new LoanEntity();

                    loanEntity.id = entityObject.optString("id");
                    loanEntity.ordersn = entityObject.optString("ordersn");
                    loanEntity.posttime = entityObject.optString("posttime");
                    loanEntity.payment = entityObject.optString("payment");
                    loanEntity.pay_state = entityObject.optString("pay_state");
                    loanEntity.pay_money = entityObject.optString("pay_money");
                    loanEntity.pay_time = entityObject.optString("pay_time");

                    loanListEntity.loanEntityList.add(loanEntity);

                }
            }

            return loanListEntity;

        }

        return null;

    }

    public static class LoanListEntity {

        public String total, knot, nkont;

        public List<LoanEntity> loanEntityList = new ArrayList<>();
    }

    public static class LoanEntity {

        public String id, ordersn, posttime, payment, pay_time, pay_money, pay_state;

    }

}
